/*
 * @Author: your name
 * @Date: 2020-07-29 21:57:41
 * @LastEditTime: 2020-07-29 22:25:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \react-hooks-app\src\demo2\userRefDom.js
 */

 /**
  * useRef 获取dom 元素，保存一个变量
  *
  *
  */
 import React, { useRef,useEffect,useState } from 'react';

 function UserRefDemo(){

  const inputDom = useRef(null)

  let [text,setText] = useState('请输入')

  const textRef = useRef()
  useEffect(()=>{
    console.log('useEffect')
    textRef.current = text
  },[text])

  console.log('reding')
  return (
    <div>
        <input type="text" ref={inputDom}></input>
        <button onClick={()=>{inputDom.current.value = 'hello world'}}>在input上展示文字</button>
        <br></br>
        <input type="text" value={text} onChange={(e)=>{setText(e.target.value)}}></input>
    </div>
  );
 }

 export default UserRefDemo
